﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'laydate', 'commonTable', 'table', 'common', 'optimizeSelectOption'], function () {
        var form = layui.form,
            $ = layui.$,
            laydate = layui.laydate,
            table = layui.table,
            commonTable = layui.commonTable,
            common = layui.common;
        var keyValue = $.request("keyValue");
        //执行一个laydate实例
        //日期范围
        laydate.render({
            elem: '#test6'
            //设置开始日期、日期日期的 input 选择器
            //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
            , range: ['#F_PlanStartTime', '#F_PlanEndTime']
            , format:'yyyy/MM/dd HH:mm:ss'
        });
        //权限字段
        common.authorizeFields('adminform');
        var listData = [];
        $(function () {
            initControl();
            if (!!keyValue) {
                common.ajax({
                    url: '/PlanManage/Order/GetFormJson',
                    dataType: 'json',
                    data: { keyValue: keyValue },
                    async: false,
                    success: function (data) {
                        common.val('adminform', data);
                        listData = data.list;
                    }
                });
            }
            else {
                var code = new Date().formatDate('yyyyMMddhhmmss');
                $('#F_OrderCode').val("OR-" + code);
            }
            commonTable.rendertable({
                elem: '#currentTableId',
                data: listData,
                defaultToolbar: [],
                toolbar: !!keyValue ? '' : '#toolbarDemo',//工具栏
                search: false,
                limit: 9999,//每页数据 默认
                page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['count'] //自定义分页布局
                    , first: false //不显示首页
                    , last: false //不显示尾页
                },
                height: 'full-225',
                filter: {
                    clearFilter: false,
                },
                cols: [[
                    { type: "checkbox", width: 50 },
                    { field: 'F_MaterialCode', title: '物料编号', minWidth: 145, sort: true },
                    { field: 'F_MaterialName', title: '物料名称', minWidth: 145, sort: true },
                    { field: 'F_NeedNum', title: '需求数量', width: 200, edit: 'text', sort: true },
                ]]
            });
            form.render();
            //行点击事件监听，控制按钮显示
            var oneList = [];//选择1条显示
            var moreList = ["NF-delete"];//多条显示
            commonTable.tableRowClick("checkbox", "currentTableFilter", "currentTableId", oneList, moreList);
        });
        wcLoading.close();
        //toolbar监听事件
        table.on('toolbar(currentTableFilter)', function (obj) {
            var data = table.checkStatus('currentTableId').data;
            if (obj.event === 'add') {  // 监听添加操作
                var parentform = window.name;
                common.modalOpen({
                    title: "添加需求",
                    url: "/PlanManage/Order/AddForm?parentform=" + parentform,
                    width: "400px",
                    height: "400px",
                });
            }
            else if (obj.event === 'delete') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                var index = parent.layer.load(0, {
                    shade: [0.5, '#000'], //0.1透明度的背景
                });
                var cacheData = table.cache.currentTableId;
                for (var i = 0; i < data.length; i++) {
                    for (var j = 0; j < cacheData.length; j++) {
                        if (data[i].F_Id == cacheData[j].F_Id) {
                            cacheData.splice(j, 1);
                            break;
                        }
                    }
                }
                common.modalMsg("操作成功", "success");
                table.reload('currentTableId', {
                    data: cacheData
                });
                parent.layer.close(index);
            }
            return false;
        });
        function initControl() {
            //此处需修改
            //绑定数据源
            //类型为下拉框时
        }

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var postData = data.field;
            postData.list = table.cache.currentTableId;
            if (!postData["F_EnabledMark"]) postData["F_EnabledMark"] = false;
            common.submitForm({
                url: '/PlanManage/Order/SubmitForm?keyValue=' + keyValue,
                param: postData,
                success: function () {
                    common.parentreload('data-search-btn');
                }
            })
            return false;
        });
    });
</script>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">订单编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_OrderCode" name="F_OrderCode" autocomplete="off" maxlength="50" lay-verify="required" placeholder="请输入订单编号" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">客户</label>
                        <div class="layui-input-block">
                            <input id="F_Customer" name="F_Customer" type="text" maxlength="50" autocomplete="off" placeholder="请输入客户" class="layui-input"/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" id="test6">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">开始日期</label>
                        <div class="layui-input-block">
                            <input id="F_PlanStartTime" name="F_PlanStartTime" type="text" maxlength="50" lay-verify="required" autocomplete="off" placeholder="请输入开始日期" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">结束日期</label>
                        <div class="layui-input-block">
                            <input id="F_PlanEndTime" name="F_PlanEndTime" type="text" maxlength="50" lay-verify="required" autocomplete="off" placeholder="请输入结束日期" class="layui-input" />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">生产天数</label>
                        <div class="layui-input-block">
                            <input type="number" pattern="[0-9]*" id="F_DayNum" name="F_DayNum" lay-verify="required|number" autocomplete="off" value="6" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">选项</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="F_EnabledMark" id="F_EnabledMark" disabled value="true" title="有效标识">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md12 layui-col-xs12 layui-hide">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <input id="F_Description" name="F_Description" class="layui-input" placeholder="请输入备注">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md12 layui-col-sm12">
                        <label class="layui-form-label required">需求列表</label>
                        <div class="layui-input-block">
                            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item text-right layui-hide">
                    <button class="layui-btn site-demo-active" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container" id="toolbar">
                    <button id="NF-add" name="NF-add" class="layui-btn layui-btn-sm data-add-btn" lay-event="add"><i class="layui-icon">&#xe642;</i>添加</button>
                    <button id="NF-delete" name="NF-delete" class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</button>
                </div>
            </script>
        </div>
    </div>
</body>

